﻿package view.popup
{
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import view.controller.*;

    public class NewSkillDialog extends View implements IDialogUI
    {
        public var tips:UrlImage;
        public var lab_VIP:Label;
        protected var uiXML:XML;
        private var item:Bitmap;
        private var _curBmd:BitmapData;
        private var oldicon:String = "";
        private var _curSkillId:int = 0;
        private var timeoutID:uint = 0;
        private var mDataList:Array;

        public function NewSkillDialog()
        {
            this.uiXML = <View>r
n	t	t	t  <UrlImage url=""skill/bg1.png"" y=""0""/>r
n	t	t	t  <UrlImage url=""skill/iconBG.png"" x=""104"" y=""42"" mouseEnabled=""false""/>r
n	t	t	t  <UrlImage url=""skill/vip.png"" x=""40"" y=""3"" var=""tips"" mouseEnabled=""false""/>r
n	t	t	t  <Label text=""点击使用"" x=""95"" y=""130"" color=""0xb8764a"" stroke=""1"" font=""SimSun"" var=""lab_VIP"" width=""98"" height=""18"" align=""center"" bold=""true"" mouseEnabled=""false""/>r
n	t	t	t</View>")("<View>
			  <UrlImage url="skill/bg1.png" y="0"/>
			  <UrlImage url="skill/iconBG.png" x="104" y="42" mouseEnabled="false"/>
			  <UrlImage url="skill/vip.png" x="40" y="3" var="tips" mouseEnabled="false"/>
			  <Label text="点击使用" x="95" y="130" color="0xb8764a" stroke="1" font="SimSun" var="lab_VIP" width="98" height="18" align="center" bold="true" mouseEnabled="false"/>
			</View>;
            this.mDataList = [];
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(this.uiXML);
            this.init();
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            return;
        }// end function

        public function init() : void
        {
            this.visible = false;
            this.x = GlobalLayer.instance.root.stageWidth / 2 - this.width + 300;
            this.y = GlobalLayer.instance.root.stageHeight - this.height - 220;
            TweenVisibleManager.instance.register(this, TweenVisibleManager.Right, TweenVisibleManager.Right, this.width + 200, 0.6);
            this.item = new Bitmap();
            this.item.x = 113;
            this.item.y = 56;
            this.addChild(this.item);
            this.tips.url = "skill/bg.png";
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        private function onUse(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_5:String = null;
            var _loc_6:String = null;
            var _loc_7:int = 0;
            var _loc_2:int = 0;
            while (_loc_2 < this.mDataList.length)
            {
                
                if (this.mDataList[_loc_2] == int(param1))
                {
                    return;
                }
                _loc_2++;
            }
            if (this.timeoutID != 0)
            {
                this.mDataList.push(int(param1));
                return;
            }
            this.mouseChildren = true;
            this.mouseEnabled = true;
            var _loc_3:* = ConfigDictionary.data.skill;
            var _loc_4:* = _loc_3[param1];
            if (_loc_3[param1])
            {
                _loc_5 = Config.getUrl("assets/images/icon/skill/" + _loc_4.icon + ".jpg", ResourceType.NORMAL);
                App.mloader3.loadBMD(_loc_5, 1, new Handler(this.loadComplete));
                this._curSkillId = int(param1);
                _loc_6 = this._curSkillId + "";
                _loc_7 = int(_loc_6.substr(3, 1));
                if (_loc_7 == 1)
                {
                }
                TweenVisibleManager.instance.changevisible(this, true);
                this.timeoutID = setTimeout(this.close, 1000);
            }
            return;
        }// end function

        private function loadComplete(param1:BitmapData) : void
        {
            this.item.bitmapData = param1;
            this._curBmd = param1;
            return;
        }// end function

        private function onClose(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function close() : void
        {
            var _loc_1:Object = null;
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            var _loc_4:Object = null;
            var _loc_5:Image = null;
            var _loc_6:Point = null;
            var _loc_7:Point = null;
            var _loc_8:Object = null;
            var _loc_9:TimelineLite = null;
            if (this.visible)
            {
                this.mouseChildren = false;
                this.mouseEnabled = false;
                _loc_1 = ModelProxy.getValue("data", "setskill");
                _loc_3 = 0;
                for (_loc_4 in _loc_1)
                {
                    
                    if (_loc_1[_loc_4][1] == this._curSkillId)
                    {
                        _loc_2 = _loc_1[_loc_4];
                        _loc_3 = int(_loc_4);
                        break;
                    }
                }
                _loc_5 = new Image();
                _loc_5.bitmapData = this._curBmd;
                _loc_6 = this.item.localToGlobal(new Point(0, 0));
                GlobalLayer.instance.root.addChild(_loc_5);
                _loc_5.x = _loc_6.x;
                _loc_5.y = _loc_6.y;
                _loc_7 = UIGlobel.pointsDic["skill"];
                if (_loc_2)
                {
                    _loc_8 = {pos:(_loc_3 - 1), type:_loc_2[0], id:_loc_2[1]};
                    _loc_9 = new TimelineLite();
                    _loc_9.append(new TweenLite(_loc_5, 3, {x:_loc_7.x - 118 + 45 * (_loc_3 - 1), y:_loc_7.y + 63, width:36, height:36}));
                    _loc_9.append(new TweenMax(_loc_5, 0.5, {glowFilter:{color:16763904, alpha:1, blurX:30, blurY:30}}));
                    _loc_9.append(new TweenMax(_loc_5, 0.5, {glowFilter:{color:16763904, alpha:0, blurX:30, blurY:30}, onComplete:this.skillRmove, onCompleteParams:[_loc_5, true, _loc_8]}));
                }
                else
                {
                    TweenLite.to(_loc_5, 2, {x:_loc_7.x + 25, y:_loc_7.y + 25, scaleX:0.2, scaleY:0.2, onComplete:this.skillRmove, onCompleteParams:[_loc_5, false, null]});
                }
            }
            TweenVisibleManager.instance.changevisible(this, false);
            PowerCheckControl.instance.showPowerUp();
            if (this.timeoutID)
            {
                clearTimeout(this.timeoutID);
                this.timeoutID = 0;
            }
            if (this.mDataList.length > 0)
            {
                this.show(this.mDataList.pop());
            }
            return;
        }// end function

        public function skillRmove(param1:Image, param2:Boolean, param3:Object) : void
        {
            if (param2)
            {
                param1.filters = null;
                ModelProxy.change("fastlist", "delayShowSkill", param3);
            }
            GlobalLayer.instance.root.removeChild(param1);
            param1 = null;
            return;
        }// end function

        private function onDown(event:MouseEvent) : void
        {
            event.stopImmediatePropagation();
            this.close();
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.x = GlobalLayer.instance.root.stageWidth / 2 - this.width + 300;
            this.y = GlobalLayer.instance.root.stageHeight - this.height - 220;
            TweenVisibleManager.instance.register(this, TweenVisibleManager.Right, TweenVisibleManager.Right, this.width + 200, 0.6);
            return;
        }// end function

    }
}
